package com.watermark.ui;

import android.graphics.Bitmap;
import android.graphics.Color;

import java.io.Serializable;

public class WaterMarkConfig implements Serializable {
    /**
     * 文字水印的画布背景颜色 默认:透明
     */
    protected int tWartMarkBackgroundColor = Color.TRANSPARENT;
    protected int tWartTextColor = Color.WHITE;
    protected int tWartTextSize = 14;

    /**
     * water mark x方向的偏移
     */
    protected int offsetX = 30;
    /**
     * water mark y方向的偏移
     */
    protected int offsetY = 30;

    /**
     * 录制时视频分辨率,默认：720p 720*1280
     */
    protected int videoSize = 720;
    // 码率
    protected int bitRate = 3500000;

    /**
     * 帧率 默认：24
     */
    protected int frameRate = 24;

    /**
     * 拍照时图片分辨率:默认：1080*1920
     */
    protected int pictureSize = 1080;

    /**
     * water mark width
     */
    protected final int waterMarkWidth;

    /**
     * water mark height
     */
    protected final int waterMarkHeight;

    /**
     * 是否可以动态更新水印
     */
    protected boolean enableUpdate = false;

    private WaterMarkConfig(int width, int height) {
        this.waterMarkHeight = height;
        this.waterMarkWidth = width;
    }

    /**
     * @param width  水印宽度
     * @param height 水印高德
     */
    public static WaterMarkConfig of(int width, int height) {
        return of(width, height, true);
    }

    public static WaterMarkConfig of(int width, int height, boolean enableUpdate) {
        WaterMarkConfig config = new WaterMarkConfig(width, height);
        config.enableUpdate = enableUpdate;
        return config;
    }

    /**
     * @param mark 图片水印
     */
    public static WaterMarkConfig of(Bitmap mark) {
        return of(mark, false);
    }

    public static WaterMarkConfig of(Bitmap mark, boolean enableUpdate) {
        WaterMarkConfig config = new WaterMarkConfig(mark.getWidth(), mark.getHeight());
        config.enableUpdate = enableUpdate;
        return config;
    }

    public void setFrameRate(int frameRate) {
        this.frameRate = frameRate;
    }

    /**
     * 视频配置
     *
     * @param videoSize 视频分辨率
     * @param mBitRate  视频码率，单位： mbps 推荐：720P:3.5
     */
    public void setVideoSize(int videoSize, double mBitRate) {
        this.videoSize = videoSize;
        this.bitRate = (int) (mBitRate * 1000 * 1000 + 0.5f);
    }

    public void setPictureSize(int pictureSize) {
        this.pictureSize = pictureSize;
    }

    public void setOffset(int offsetX, int offsetY) {
        this.offsetX = offsetX;
        this.offsetY = offsetY;
    }

    /**
     * @param textSize    文字大小
     * @param textColor   文字颜色
     * @param canvasColor 画布背景色
     */
    public void settWartMarkBackgroundColor(int textSize, int textColor, int canvasColor) {
        this.tWartMarkBackgroundColor = canvasColor;
        this.tWartTextColor = textColor;
        this.tWartTextSize = textSize;
    }

    public int getWartMarkBackgroundColor() {
        return tWartMarkBackgroundColor;
    }

    public int getWartTextColor() {
        return tWartTextColor;
    }

    public int getWartTextSize() {
        return tWartTextSize;
    }

    public int getOffsetX() {
        return offsetX;
    }

    public int getOffsetY() {
        return offsetY;
    }

    public int getVideoSize() {
        return videoSize;
    }

    public int getBitRate() {
        return bitRate;
    }

    public int getFrameRate() {
        return frameRate;
    }

    public int getPictureSize() {
        return pictureSize;
    }

    public int getWaterMarkWidth() {
        return waterMarkWidth;
    }

    public int getWaterMarkHeight() {
        return waterMarkHeight;
    }

    public boolean isEnableUpdate() {
        return enableUpdate;
    }
}
